package com.meilai.project.controller.mini;

import com.meilai.project.controller.mini.dto.LoginParams;
import com.meilai.project.dto.CommonResult;
import com.meilai.project.dto.base.ApiResult;
import com.meilai.project.dto.system.SignInParam;
import com.meilai.project.service.system.LoginService;
import com.meilai.project.service.system.MiniRightService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;


@Api(tags = "小程序-登录")
@RestController
@RequestMapping("api/mini/login")
public class MiniLoginController {

    @Autowired
    private LoginService loginService;

    @Autowired
    private MiniRightService miniRightService;

    @ApiOperation(value = "登录")
    @PostMapping("sign-in")
    public ApiResult<SignInParam> login(@Valid @RequestBody LoginParams dto, HttpServletRequest request){
        return ApiResult.ok(loginService.miniLogin(request, dto.getUsername(), dto.getPassword()));
    }

    @GetMapping("query-rights")
    @ApiOperation(value = "整个权限树")
    public CommonResult miniRights(){
        return new CommonResult().success(miniRightService.getMyRights());
    }
}
